package com.csf.cs.pipeline;

import static org.jboss.netty.channel.Channels.pipeline;

import javax.net.ssl.SSLEngine;

import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.handler.ssl.SslHandler;

import com.csf.common.decoder.HeaderLengthBasedFrameDecoder;
import com.csf.common.protobuff.deseralizer.ProtoBuffDeserialiser;
import com.csf.common.protobuff.serialiser.ProtoBuffSerialiser;
import com.csf.cs.core.ssl.ServerSSLContextFactory;

public class PipeLineFactory implements ChannelPipelineFactory{

	public ChannelPipeline getPipeline() throws Exception {
		ChannelPipeline pipeline = pipeline();
		
		//ssl support
		SSLEngine engine =
			              ServerSSLContextFactory.getServerContext().createSSLEngine();
			          engine.setUseClientMode(false);
			          pipeline.addLast("ssl", new SslHandler(engine));

	    //upstream
		pipeline.addLast("framedecoder", new HeaderLengthBasedFrameDecoder());
		//pipeline.addLast("objectdecoder", new MyMessageDecoder());
		//pipeline.addLast("serverhandler", new MyServerHandler());
		pipeline.addLast("serverhandler", new ProtoBuffDeserialiser());
		//downstream
		pipeline.addLast("encoder", new ProtoBuffSerialiser());
		return pipeline;
	}
	
	
}
